//1. set this to the desired path
*cd "~/Desktop/LAP_PSRM_Replication/"

//2. Import the core replication file
use "LAP_Replication_MatchedBills_COOHWI.dta", clear

//3. Extract the year so it can used as a fixed effect
gen year = substr(bill_id,4,4)

//4. Transform the average sponsor ideal point to a measure of extremity.
// Multiple liberal (negative) scores by negative one, so it resembles an absolute value, without assuming zero is the midpoint)
gen spon_ext = spon_mean
replace spon_ext = spon_mean * -1 if spon_mean < 0 

//5. Create a unique identifer of the two-state dyad 
gen state_combo = ustrleft(state,2) +"_"+ustrright(M_state,2)

//6. Run a regression to establish the sample
global Minsamp "salient spon_ext, absorb(sg_v) cluster(bill_id)"

//7. standardize the sample
eststo clear
eststo: reghdfe party_diff M_lorgs* lorgs* $Minsamp
rename _est_est1 insamp

//8. Run the regressions
global Mcontrols "salient spon_ext if insamp == 1, absorb(sg_v state_combo year) cluster(bill_id)"
eststo clear
eststo: reghdfe party_diff lorgs* $Mcontrols
eststo: reghdfe party_diff M_lorgs* $Mcontrols
eststo: reghdfe party_diff M_lorgs* lorgs* $Mcontrols

//8. Table 4
esttab , se replace label ///
mtitles("actual" "placebo" "both") ///
b(2) se(2) ///
nodepv ///
star(* 0.05 ** 0.01) ///
 order( lorgs_N M_lorgs_N lorgs_B M_lorgs_B lorgs_G M_lorgs_G salient spon_ext)

 //9. Limit the sample to passage votes for Figure 2
 gen insamp2 = insamp
 replace insamp2 = 0 if sg_vote != 2
 
 //10. Create Figure 2
 twoway ///
	(scatter party_diff lorgs_N if insamp2, mcolor(black%40) msymbol(D) jitter(2)) ///
	(lfit party_diff lorgs_N if insamp2, lcolor(black) lpattern(solid) range(1.3 4)) ///
	(scatter party_diff M_lorgs_N if insamp2, mcolor(blue%30) msymbol(Oh) jitter(2)) ///
	(lfit party_diff M_lorgs_N if insamp2, lcolor(blue) lpattern(dash) range(0 4)), ///
	legend(order(1 "Actual groups" 2 "Actual fit" 3 "Placebo groups" 4 "Placebo fit")) ///
	ytitle("Party Difference on passage votes") xtitle("No. of non-profit groups lobbying (log)") 
	
